package com.example.tbs.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.tbs.common.ServerResponse;
import com.example.tbs.demo.entity.TbsFl;
import com.example.tbs.demo.service.ITbsService;
import jakarta.annotation.Resource;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.apache.velocity.exception.ResourceNotFoundException;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tbs")
public class TbsController {
        @Resource
        private ITbsService tbsService;

        @PostMapping("/calculate")
        public ResponseEntity<String> calculateBilling() {
                tbsService.calculateBilling();
                return ResponseEntity.ok("费用计算完成");
        }
        // RESTful 接口
        @GetMapping("/api/billing/info")
        public ServerResponse getBillingInfo(String phoneNumber) {
                final var billingInfo = tbsService.getBillingInfo(phoneNumber);
                return billingInfo;
        }
        @GetMapping("/rate")
        public BigDecimal getRate(@RequestParam String areaCode) {
                return tbsService.getRateByAreaCode(areaCode);
        }
        @GetMapping("/api/billing/records")
        public ServerResponse getCallRecords(String phoneNumber) {
                final var callRecords = tbsService.getCallRecords(phoneNumber);
                return callRecords;
        }



//        // 示例：返回页面并传递数据
//        @GetMapping("/billing/info/{phoneNumber}")
//        public String showBillingInfo(@PathVariable String phoneNumber, Model model) {
//                Map<String, Object> billingInfo = tbsService.getBillingInfo(phoneNumber);
//                model.addAttribute("billingInfo", billingInfo);
//                return "billing-info"; // 返回费用查询页面并传递数据
//        }
}
